package main

import (
	"fmt"
	"log"
	"regexp"
	"strings"
	_ "strings"
)

func main() {
	//fmt.Println()
	//print("Hello ,Go!")
	//println(len("123"))
	//a := []int{1, 2, 3}
	//println(cap(a))
	//b := make([]string, 0, 10)
	//fmt.Printf("len: %d, cap: %d", len(b), cap(b))

	// 正则完整匹配测试
	words := []string{"1", "1111", "11111", "123w", "w123", "www", "1111r1111"}

	re, err := regexp.Compile("[0-9]{1,4}")

	if err != nil {
		log.Fatal(err)
	}
	for _, word := range words {
		//found := re.Match([]byte(word))
		//if found {
		//	fmt.Printf("%s matches \n", word)
		//} else {
		//	fmt.Printf("%s does not match \n", word)
		//}

		parts := re.FindAllStringSubmatch(word, 1)
		if len(parts) == 1 {
			if compareStringSlice(parts[0], word) {
				fmt.Printf("%s matches one ", word)
			}
		}
		//fmt.Println(len(parts))
		for i := range parts {
			fmt.Println(i)
			fmt.Println(parts[i])
		}
		fmt.Println("-------------")
	}
}
func compareStringSlice(s1 []string, s2 string) bool {
	if len(s1) == 0 && len(s2) == 0 {
		return true
	}
	str1 := strings.Join(s1, ",")
	return str1 == s2
}
